package com.jhgsys.internal.incentive.service.impl;

import com.jhgsys.internal.incentive.entity.IncentiveRewardAuditRecord;
import com.jhgsys.internal.incentive.mapper.IncentiveRewardAuditRecordMapper;
import com.jhgsys.internal.incentive.service.IIncentiveRewardAuditRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 安全奖励审核记录 Service实现
 *
 * @author wanghjw
 * @date 2024-09-03 14:08:27
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class IncentiveRewardAuditRecordServiceImpl extends ServiceImpl<IncentiveRewardAuditRecordMapper, IncentiveRewardAuditRecord> implements IIncentiveRewardAuditRecordService {

    /**
     * 查询（分页）
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     * @param request QueryRequest
     * @param incentiveRewardAuditRecord incentiveRewardAuditRecord
     * @return IPage<IncentiveRewardAuditRecord>
    */
    @Override
    public IPage<IncentiveRewardAuditRecord> findIncentiveRewardAuditRecordPage(QueryRequest request, IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
        LambdaQueryWrapper<IncentiveRewardAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveRewardAuditRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<IncentiveRewardAuditRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     * @param incentiveRewardAuditRecord incentiveRewardAuditRecord
     * @return List<IncentiveRewardAuditRecord>
     */
    @Override
    public List<IncentiveRewardAuditRecord> findIncentiveRewardAuditRecordList(IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
	    LambdaQueryWrapper<IncentiveRewardAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveRewardAuditRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author wanghjw
    * @date 2024-09-03 14:08:27
    * @param id
    * @return IncentiveRewardAuditRecord
    */
    @Override
    public IncentiveRewardAuditRecord findIncentiveRewardAuditRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     * @param incentiveRewardAuditRecord incentiveRewardAuditRecord
     */
    @Override
    @Transactional
    public void createIncentiveRewardAuditRecord(IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
        incentiveRewardAuditRecord.setCreatedTime(new Date());
        this.save(incentiveRewardAuditRecord);
    }

    /**
     * 修改
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     * @param incentiveRewardAuditRecord incentiveRewardAuditRecord
     */
    @Override
    @Transactional
    public void updateIncentiveRewardAuditRecord(IncentiveRewardAuditRecord incentiveRewardAuditRecord) {
        incentiveRewardAuditRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(incentiveRewardAuditRecord);
    }

    /**
     * 逻辑删除
     * @author wanghjw
     * @date 2024-09-03 14:08:27
     * @param incentiveRewardAuditRecord incentiveRewardAuditRecord
     * @param incentiveRewardAuditRecordIds incentiveRewardAuditRecordIds
     */
    @Override
    @Transactional
    public void deleteIncentiveRewardAuditRecord(IncentiveRewardAuditRecord incentiveRewardAuditRecord,String incentiveRewardAuditRecordIds) {
        List<String> list = Arrays.asList(incentiveRewardAuditRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(incentiveRewardAuditRecord,new LambdaQueryWrapper<IncentiveRewardAuditRecord>().in(IncentiveRewardAuditRecord::getRewardAuditRecordId,list));
	}

    /**
    * 物理删除
    * @author wanghjw
    * @date 2024-09-03 14:08:27
    * @param incentiveRewardAuditRecordIds incentiveRewardAuditRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteIncentiveRewardAuditRecord(String incentiveRewardAuditRecordIds) {
        List<String> list = Arrays.asList(incentiveRewardAuditRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<IncentiveRewardAuditRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(IncentiveRewardAuditRecord::getRewardAuditRecordId,list);
        this.remove(wapper);
    }
}
